package com.pijunn.report

class ReportService {
	boolean transactional = false
	
    def countLostReports(Boolean closed) {
		return LostEvent.withCriteria {
			closed ? isNull('foundTime') : isNotNull('foundTime')
			projections {
				rowCount()
			}
		}
    }
	
    def countFoundReports(String property) {
		def open = FoundEvent.withCriteria {
			isNull(property)
			projections {
				'open'
				rowCount()
			}
		}
		
		def closed = FoundEvent.withCriteria {
			isNotNull(property)
			projections {
				'closed'
				rowCount()
			}
		}

		open + closed
    }
	
	def listOpenLostEvents() {
		LostEvent.findAllByFoundTimeIsNull()
	}
	
	def listOpenFoundEvents() {
		FoundEvent.findAllByLoserRespondTimeIsNull()
	}
}
